# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=linux-headers
pkgver=6.6 # Follow the latest Linux stable
case $pkgver in
	*.*.*)	_kernver=${pkgver%.*};;
	*.*) _kernver=$pkgver;;
esac
pkgrel=0
pkgdesc="Linux system headers"
url="https://kernel.org/"
arch="noarch"
license="GPL-2.0-only"
makedepends="perl"
options="!check !dbg !strip !tracedeps"
source="https://kernel.org/pub/linux/kernel/v6.x/linux-$_kernver.tar.xz
	revert-broken-uapi.patch
	0003-remove-inclusion-of-sysinfo.h-in-kernel.h.patch
	"
if [ "${pkgver%.0}" = "$pkgver" ]; then
	source="
		$source
		https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/patch-$pkgver.xz
		"
fi
builddir="$srcdir/linux-$_kernver"

_carch="$CARCH"
case "$_carch" in
aarch64*) _carch="arm64" ;;
arm*) _carch="arm" ;;
mips*) _carch="mips" ;;
s390*) _carch="s390" ;;
ppc*) _carch="powerpc" ;;
riscv*) _carch="riscv" ;;
# not sure about this --	ppc64*) _carch="powerpc64" ;;
esac

prepare() {
	if [ "$_kernver" != "$pkgver" ]; then
		unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1
	fi
	default_prepare
}

build() {
	make headers ARCH="$_carch"
}

package() {
	mkdir -p "$pkgdir"/usr/
	cp -a usr/include/ "$pkgdir"/usr/include/

	msg "purging non header files.."
	find "$pkgdir"/usr/include/ ! -iname "*.h" -type f -exec rm -v {} \+

	# provided by libdrm
	rm -rf "$pkgdir"/usr/include/drm
}

sha512sums="
458b2c34d46206f9b4ccbac54cc57aeca1eaecaf831bc441e59701bac6eadffc17f6ce24af6eadd0454964e843186539ac0d63295ad2cc32d112b60360c39a35  linux-6.6.tar.xz
32597f2672d1ec365a936d15041a7cf219ef9353241d4a5c378244cf2fc155610443a19bbcd391c86099a0b08486c45e042ec7c90b0d04fe675c3ad0ffc36b53  revert-broken-uapi.patch
607c074d72aca88fea9ecdbd62198d8f7857daca75e5d027966e0a9997338d6ac8ce0a1e9114b19232b390751d05acca09e28b0cfad2a12d5942f5575a9f4684  0003-remove-inclusion-of-sysinfo.h-in-kernel.h.patch
1898e06d074961ab3919de9408cdb9bcb359194e3c5d7de78e9a2dd20457a3f55e2bf1d8a9c1689d3117353b095d6b63a29ff7d9874ac35c7deb7a2155bcbf72  patch-6.6.xz
"
